package cn.com.jcoo.exception;

import lombok.Getter;

import java.text.MessageFormat;

/**
 * 默认系统异常
 */
@Getter
public class SysException extends RuntimeException implements ISysError {
    private final String scope;
    private final Integer code;
    private final String message;

    public static String format(String scope, int code, String message) {
        return MessageFormat.format(MESSAGE_TEMPLATE, scope, code, message);
    }

    public SysException(String message) {
        this.scope = "系统异常";
        this.code = DEFAULT_CODE;
        this.message = message;
    }

    public SysException(Integer code, String message) {
        this.scope = "系统异常";
        this.code = code;
        this.message = message;
    }
    public SysException(Throwable throwable) {
        this.scope = "系统异常";
        this.code = DEFAULT_CODE;
        this.message = throwable.getMessage();
    }

    public SysException(String scope, Integer code, String message) {
        this.scope = scope;
        this.code = code;
        this.message = message;
    }

    public String getMessage() {
        return format(scope, code, message);
    }
}
